package com.hzhr.iot.collect.constant.entity.constant;


import com.hzhr.iot.collect.constant.entity.FunctionEntity;
import com.hzhr.iot.collect.constant.entity.FunctiontmpEntity;

import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

public class FunctionEntityConstant {
	public static Map<Integer, FunctionEntity> MAP = new HashMap<Integer, FunctionEntity>() {
		private static final long serialVersionUID = 1L;

		{
			putAll(getEntityMap(getEntity(1, "9033", 1, 1, 1, 10000171, 10000171, 10000171, 20000001)));
			putAll(getEntityMap(getEntity(2, "9001", 1, 2, 2, 10000182, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(3, "9011", 1, 3, 3, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(4, "9012", 1, 4, 4, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(5, "9015", 1, 5, 5, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(6, "9016", 1, 6, 6, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(7, "9041", 1, 7, 7, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(8, "9042", 1, 8, 8, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(9, "9034", 1, 9, 9, 10000171, 10000171, 10000171, 20000001)));
			putAll(getEntityMap(getEntity(10, "9013", 1, 10, 10, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(11, "9014", 1, 11, 11, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(12, "9021", 1, 12, 12, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(13, "9022", 1, 13, 13, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(14, "9031", 1, 14, 14, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(15, "9032", 1, 15, 15, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(16, "9051", 1, 16, 16, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(17, "9052", 1, 17, 17, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(18, "9053", 1, 18, 18, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(19, "9043", 1, 19, 19, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(20, "9035", 1, 20, 20, 10000171, 10000182, 10000182, 20000001)));

			putAll(getEntityMap(getEntity(21, "1004", 2, 21, 21, 10000171, 10000171, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(22, "1001", 2, 22, 22, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(23, "1002", 2, 23, 23, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(24, "1003", 2, 24, 24, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(25, "1011", 2, 25, 25, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(26, "1012", 2, 26, 26, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(27, "1015", 2, 27, 27, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(28, "1016", 2, 28, 28, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(29, "1013", 2, 29, 29, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(30, "1014", 2, 30, 30, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(31, "1017", 2, 31, 31, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(32, "1018", 2, 32, 32, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(33, "1023", 2, 33, 33, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(34, "1024", 2, 34, 34, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(35, "1042", 2, 35, 35, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(36, "1043", 2, 36, 36, 10000171, 10000182, 10000171, 20000002)));
			putAll(getEntityMap(getEntity(37, "1051", 2, 37, 37, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(38, "1052", 2, 38, 38, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(39, "1053", 2, 39, 39, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(40, "1062", 2, 40, 40, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(41, "1063", 2, 41, 41, 10000171, 10000182, 10000182, 20000002)));

			putAll(getEntityMap(getEntity(42, "01", 3, 42, 42, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(43, "10", 3, 43, 43, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(44, "11", 3, 44, 44, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(45, "12", 3, 45, 45, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(46, "13", 3, 46, 46, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(47, "14", 3, 47, 47, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(48, "15", 3, 48, 48, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(49, "16", 3, 49, 49, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(50, "17", 3, 50, 50, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(51, "21", 3, 51, 51, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(52, "31", 3, 52, 52, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(53, "32", 3, 53, 53, 10000171, 10000182, 10000171, 20000002)));
			putAll(getEntityMap(getEntity(54, "33", 3, 54, 54, 10000171, 10000182, 10000171, 20000002)));
			putAll(getEntityMap(getEntity(55, "41", 3, 55, 55, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(56, "42", 3, 56, 56, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(57, "43", 3, 57, 57, 10000171, 10000182, 10000182, 20000002)));

			putAll(getEntityMap(getEntity(58, "2003", 2, 58, 58, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(59, "2004", 2, 59, 59, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(60, "2011", 2, 60, 60, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(61, "2012", 2, 61, 61, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(62, "2015", 2, 62, 62, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(63, "2016", 2, 63, 63, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(64, "2042", 2, 64, 64, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(65, "2051", 2, 65, 65, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(66, "2052", 2, 66, 66, 10000171, 10000182, 10000182, 20000002)));
			putAll(getEntityMap(getEntity(67, "2053", 2, 67, 67, 10000171, 10000182, 10000182, 20000002)));

			putAll(getEntityMap(getEntity(68, "9010", 1, 68, 68, 10000171, 10000182, 10000182, 20000001)));

			putAll(getEntityMap(getEntity(69, "1025", 2, 69, 69, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(70, "1026", 2, 70, 70, 10000171, 10000182, 10000182, 20000001)));

			putAll(getEntityMap(getEntity(71, "2033", 2, 71, 71, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(72, "2034", 2, 72, 72, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(73, "2036", 2, 73, 73, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(74, "2041", 2, 74, 74, 10000171, 10000182, 10000182, 20000001)));

			putAll(getEntityMap(getEntity(75, "2003", 4, 75, 58, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(76, "2004", 4, 76, 59, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(77, "2005", 4, 77, 77, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(78, "2011", 4, 78, 60, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(79, "2012", 4, 79, 61, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(80, "2015", 4, 80, 62, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(81, "2016", 4, 81, 63, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(82, "2042", 4, 82, 64, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(83, "2051", 4, 83, 65, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(84, "2052", 4, 84, 66, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(85, "2053", 4, 85, 67, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(86, "2061", 4, 86, 86, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(87, "2062", 4, 87, 87, 10000171, 10000182, 10000182, 20000001)));

			putAll(getEntityMap(getEntity(88, "2061", 2, 88, 86, 10000171, 10000182, 10000182, 20000001)));
			putAll(getEntityMap(getEntity(89, "2062", 2, 89, 87, 10000171, 10000182, 10000182, 20000001)));

		}
	};
	
	public static FunctionEntity getFunctionEntityByProtocolIdAndFunctionCode(Integer protocolId, String functionCode) {
		if (protocolId == null || functionCode == null) return null;
		Map<Integer, FunctionEntity> map = MAP;
		for (Map.Entry<Integer, FunctionEntity> entry : map.entrySet()) {
			FunctionEntity functionEntity = entry.getValue();
			if (protocolId.equals(functionEntity.getProtocolId()) && functionCode.equals(functionEntity.getCode())) 
				return functionEntity;
		}
		return null;
	}
	
	public static FunctionEntity getFunctionEntityByProtocolIdAndFunctiontmpId(Integer protocolId, Integer functiontmpId) {
		if (protocolId == null || functiontmpId == null) return null;
		Map<Integer, FunctionEntity> map = MAP;
		for (Map.Entry<Integer, FunctionEntity> entry : map.entrySet()) {
			FunctionEntity functionEntity = entry.getValue();
			if (protocolId.equals(functionEntity.getProtocolId()) && functiontmpId.equals(functionEntity.getFunctiontmpId())) 
				return functionEntity;
		}
		return null;
	}
	
	private static FunctionEntity getEntity(Integer id, String code, Integer protocolId, Integer dataareatmpId,
			Integer functiontmpId, Integer isautoresp, Integer issendmsg, Integer iswaitresp, Integer commmode) {
		FunctionEntity functionEntity = new FunctionEntity();
		functionEntity.setId(id);
		functionEntity.setCode(code);
		functionEntity.setProtocolId(protocolId);
		functionEntity.setDataareatmpId(dataareatmpId);
		functionEntity.setFunctiontmpId(functiontmpId);
		functionEntity.setIsautoresp(isautoresp);
		functionEntity.setIssendmsg(issendmsg);
		functionEntity.setIswaitresp(iswaitresp);
		functionEntity.setCommmode(commmode);
		return functionEntity;
	}
	
	private static Map<Integer, FunctionEntity> getEntityMap(FunctionEntity messagefieldEntity) {
		Map<Integer, FunctionEntity> map = new HashMap<>();
		map.put(messagefieldEntity.getId(), messagefieldEntity);
		return map;
	}

	public static Map<String, String> getCodeNameMapByType(String type) {
		Map<Integer, FunctiontmpEntity> map = FunctiontmpEntityConstant.MAP;
		SortedMap<String, String> result = new TreeMap<String, String>();


		for (Map.Entry<Integer, FunctiontmpEntity> entry : map.entrySet()) {
			Integer id = (Integer)entry.getKey();
			FunctiontmpEntity value = (FunctiontmpEntity)entry.getValue();
			if ("concentrator".equals(type) && value.getName().startsWith("集中器 ")) {
				FunctionEntity functionEntity = getFunctionEntityByFunctiontmpId(id);
				if (functionEntity != null) {
					result.put(functionEntity.getCode(), value.getName());
				}
			}
		}

		return result;
	}
	public static FunctionEntity getFunctionEntityByFunctiontmpId(Integer functiontmpId) {
		if (functiontmpId == null) return null;
		Map<Integer, FunctionEntity> map = MAP;
		for (Map.Entry<Integer, FunctionEntity> entry : map.entrySet()) {
			FunctionEntity functionEntity = (FunctionEntity)entry.getValue();
			if (functiontmpId.equals(functionEntity.getFunctiontmpId()))
				return functionEntity;
		}
		return null;
	}
}
